﻿Imports OpenHardwareMonitor.Hardware

Public Class frmSelect

#Region " Declerations "

	Dim get_GPU_Info As New GPU_Info_Extractor.GPUMonitor_Extractor

#End Region

#Region " Functions "

	Private Sub loadsettings()

		Try

			If frmSettings.checkValidity_Range(True) = False Then
				frmSettings.setDefaults_Range()
				MsgBox("Settings Currupted ,Defaults will be Loaded", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Warning-Wrong Ranges")

			End If

			If frmSettings.checkValidity_Color(True) = False Then
				frmSettings.setDefaults_Color()
				MsgBox("Settings Currupted ,Defaults will be Loaded", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Warning-Wrong Colors")

			End If
			Me.Icon = My.Resources.GPU
			PicBoxAurora.BackgroundImage = My.Resources.Logo_Highlight
			Me.BackgroundImage = My.Resources.Background


			If My.Settings.FirstRun = True Then
				My.Settings.FirstRun = False
				Me.Show()
				timrStart.Enabled = True
			Else
				If (My.Settings.startup = True AndAlso My.Settings.minimize = True) Then
					frmTaskBar.Show()
					frmTaskBar.CMS_Start.PerformClick()
					timrEnd.Enabled = True

				ElseIf (My.Settings.remember = True) Then
					If My.Settings.toLoad = 0 Then
						frmMain.Show()
						timrEnd.Enabled = True
					ElseIf My.Settings.toLoad = 1 Then
						frmTaskBar.Show()
						frmTaskBar.CMS_Start.PerformClick()
						timrEnd.Enabled = True
					End If

				ElseIf (My.Settings.remember = False) Then
					Me.Show()
					timrStart.Enabled = True
				Else
					MsgBox("Settings Currupted ", MsgBoxStyle.OkOnly, "Error")
					Me.Show()
					timrStart.Enabled = True
				End If


			End If
		Catch ex As Exception
			MsgBox("GPU Monitor is Unable to load Settings,will now Exit ", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "Aurora GPU Monitor")
			End

		End Try

	End Sub

	Private Sub checkGPU()
		If Not (get_GPU_Info.getFromOpenHardwareMonitor_GPUType = HardwareType.GpuAti OrElse get_GPU_Info.getFromOpenHardwareMonitor_GPUType = HardwareType.GpuNvidia) Then
			MsgBox("No supported GPU Detected ,GPU Monitor will Exit ", MsgBoxStyle.OkOnly, "Aurora GPU Monitor")
			End
		Else
			loadsettings()

		End If
	End Sub

#End Region

#Region " Form "

	Private Sub frmSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Try
			Me.Hide()
			Me.Opacity = 0
			checkGPU()
		Catch ex As Exception

		End Try
	End Sub

	Private Sub frmSelect_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
		Try
			If e.KeyCode = Keys.Escape Then
				timrEnd.Enabled = True
			End If
		Catch ex As Exception

		End Try

	End Sub

	Private Sub frmSelect_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
		Try

			timrEnd.Enabled = True
			Exit Sub
		Catch ex As Exception

		End Try
	End Sub

#End Region

#Region " GUI "

	Private Sub PicBoxClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Try
			timrEnd.Enabled = True
		Catch ex As Exception

		End Try
	End Sub

	Private Sub btnMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMain.Click
		Try

			If chkBxRemember.Checked Then
				My.Settings.remember = True
				My.Settings.toLoad = 0

			Else
				My.Settings.remember = False
			End If
			My.Settings.Save()
			frmMain.Show()
			timrEnd.Enabled = True
		Catch ex As Exception

		End Try
	End Sub



	Private Sub btnNotificationBar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNotificationBar.Click
		Try

			If get_GPU_Info.ThermalSensorPresent = True Then
				If chkBxRemember.Checked Then
					My.Settings.remember = True
					My.Settings.toLoad = 1
					My.Settings.minimize = True
				Else
					My.Settings.remember = False
				End If
				My.Settings.Save()


				frmTaskBar.Show()
				frmTaskBar.CMS_Start.PerformClick()
				timrEnd.Enabled = True
			Else
				MsgBox("No GPU thermal sensor was detected", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, " Ops ")
			End If

		Catch ex As Exception

		End Try
	End Sub

	Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
		Try
			About.ShowDialog()
		Catch ex As Exception

		End Try
	End Sub

	Private Sub PicBoxAurora_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PicBoxAurora.Click
		Try
			timrEnd.Enabled = True
		Catch ex As Exception

		End Try
	End Sub

#End Region

#Region " Timers "

	Private Sub timrStart_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timrStart.Tick
		Try
			Me.Opacity = Me.Opacity + 0.1
			If Me.Opacity >= 0.8 Then
				timrStart.Enabled = False
			End If
		Catch ex As Exception

		End Try
	End Sub

	Private Sub timrEnd_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timrEnd.Tick
		Try
			Me.Opacity = Me.Opacity - 0.1
			If Me.Opacity <= 0 Then
				timrStart.Enabled = False
				Me.Close()
			End If
		Catch ex As Exception

		End Try
	End Sub

#End Region

	
End Class